/*
 * Dijjer - A Peer to Peer HTTP Cache
 * Copyright (C) 2004,2005 Change.Tv, Inc
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package dijjer.util.logging;

public class Level {

	public static final String VERSION = "$Id: Level.java 2 2008-03-21 14:33:03Z ian.clarke $";

	private boolean _active = true;

	public static final Level DEBUG = new Level("DEBUG", false);
	public static final Level INIT = new Level("INIT", true);
	public static final Level INFO = new Level("INFO", true);
	public static final Level OUTPUT = new Level("OUTPUT", true);
	public static final Level WARNING = new Level("WARNING", true);
	public static final Level ERROR = new Level("ERROR", true);
	public static final Level FATAL = new Level("FATAL", true);
	public static final Level UNDEFINED = new Level("UNDEFINED", true);

	private static final Level[] _levels = new Level[] {
		DEBUG, INIT, INFO, OUTPUT, WARNING, ERROR, FATAL
	};

	private final String _name;

	private Level(String name, boolean active) {
		_name = name;
		_active = active;
}

	public String toString() {
		return _name;
	}

	public boolean isError() {
		return this == WARNING || this == ERROR || this == FATAL;
	}

	public void setActive(boolean active) {
		_active = active;
	}

	public boolean isActive() {
		return _active;
	}

	public static Level[] values() {
		return _levels;
	}

	public static Level getLevel(String level) {
		for (int i = 0; i < _levels.length; i++) {
			if (_levels[i].toString().equalsIgnoreCase(level)) {
				return _levels[i];
			}
		}
		return UNDEFINED;
	}
}
